const usersModel = require('../model/usersModle.js')
const addressesModel = require('../model/addressesModel.js')

//增加
module.exports.insert = async function (addresses) {
    return await addressesModel.create(addresses)
}

//删除
module.exports.delete = async function (id) {
    return await addressesModel.deleteOne({ _id: id })
}

//修改
module.exports.update = async function (id,addresses) {
    return await addressesModel.updateOne({ _id: id },addresses)
}

//查询 查询所有
module.exports.findAll = async function () {
    return  await addressesModel.find().populate({ path: "userId", model: usersModel })
}

//通过userId 查询所有
module.exports.findByuser = async function (userId) {
    return  await addressesModel.find(userId).populate({ path: "userId", model: usersModel })
}
